<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="renderer" content="webkit">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10, user-scalable=yes">
	<meta name="description" content="">
	<meta name="keywords" content="">
	<link rel="shortcut icon" href="./favicon.ico"/>
	<link rel="bookmark" href="./favicon.ico"/>
	<!--<title>True Numbers Marker</title>-->
	<title>True Data Marker</title>
	<link rel="stylesheet" type="text/css" href="assets/css/reset.css">
	<link rel="stylesheet" type="text/css" href="assets/css/font-awesome-4.5.0/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="assets/css/animate.css">
	<link rel="stylesheet" type="text/css" href="assets/css/plugins.css">
	<link rel="stylesheet" type="text/css" href="assets/js/plugins/handsontable/handsontable.full.min.css">
	<link rel="stylesheet" type="text/css" href="assets/css/app.css">
	<style>
		td.formula {
		  background-color: yellow;
		}
		td.formula-error {
		  background-color: red;
		}
		#loading{
			position: absolute;
			left: 50%;
			top: 50%;
			width: 100px;
			height: 100px;
			margin-top: -50px;
			margin-left: -50px;
			z-index: 999999;
			color: #02B061;
			display: none;
			text-align: center;
			line-height: 100px;
			font-size: 30px;
		}
		#loading span{
			width: 100%;
			height: 100%;
			border-radius: 10px;
			background-color: rgba(200,200,200,0.6);
			position: absolute;
			left: 0;
			top: 0;
			z-index: -1;
		}
	</style>
</head>
<body>
	<div class="app-warper">
		<header>
			<!--Numbers-->
			<h1 class="app-logo">True <b class="app-name">Data</b></h1>
			<div class="app-top-left app-toolbar">
				<div class="toolbar-item sheets-view-scale">
					<span id="view-scale" class="view-scale-cont">100%</span>
					<i class="fa fa-caret-down"></i>
					<div class="popup-warper scale-popup">
						<ul class="popup-cont">
							<li class="popup-item cmd-scale" data-scale="0.25">25%</li>
							<li class="popup-item cmd-scale" data-scale="0.50">50%</li>
							<li class="popup-item cmd-scale" data-scale="0.75">75%</li>
							<li class="popup-item cmd-scale active" data-scale="1">100%</li>
							<li class="popup-item cmd-scale" data-scale="1.25">125%</li>
							<li class="popup-item cmd-scale" data-scale="1.5">150%</li>
							<li class="popup-item cmd-scale" data-scale="2">200%</li>
							<li class="popup-item cmd-scale" data-scale="3">300%</li>
							<li class="popup-item cmd-scale" data-scale="4">400%</li>
						</ul>
					</div>
				</div>
				<span class="toolbar-item splitline">&nbsp;</span>
				<span data-tips="撤销" class="toolbar-item undo disable">
					<i class="fa fa-undo"></i>
				</span>
				<span data-tips="重做" class="toolbar-item redo disable">
					<i class="fa fa-repeat"></i>
				</span>
			</div>
			<div class="app-top-right app-toolbar">
				<div class="toolbar-item user-info">
					<span class="user-info-cont">菜单</span>
					<i class="fa fa-angle-down"></i>
					<div class="popup-warper">
						<ul class="popup-cont">
							<li id="new-btn" class="popup-item"><i class="fa fa-file"></i> 新建</li>
							<li id="open-btn" class="popup-item"><i class="fa fa-folder-open"></i> 打开</li>
							<li id="save-btn" class="popup-item"><i class="fa fa-save"></i> 保存</li>
							<li id="save-btn" class="popup-item"><i class="fa fa-database"></i> 数据源配置</li>
							<li id="save-btn" class="popup-item"><i class="fa fa-bars"></i> 文件属性</li>
						</ul>
					</div>
				</div>
				<span class="toolbar-item splitline">&nbsp;</span>
				<div class="toolbar-item user-info">
					<span class="user-info-cont">chen</span>
					<i class="fa fa-angle-down"></i>
					<div class="popup-warper">
						<ul class="popup-cont">
							<li class="popup-item"><i class="fa fa-cog"></i> 设置</li>
							<li class="popup-item"><i class="fa fa-sign-out"></i> 注销</li>
						</ul>
					</div>
				</div>
				<span class="toolbar-item splitline">&nbsp;</span>
				<div class="toolbar-item system-info">
					<i class="fa fa-question-circle fa-lg"></i>
					<div class="popup-warper">
						<ul class="popup-cont">
							<li class="popup-item system-info-btn"><i class="fa fa-book"></i>了解详情</li>
							<li class="popup-item system-help-btn"><i class="fa fa-question"></i>获取帮助</li>
							<li class="popup-item system-feedback-btn"><i class="fa fa-book"></i>发送反馈</li>
							<li class="popup-item system-service-btn"><i class="fa fa-comments"></i>服务和支持</li>
						</ul>
					</div>
				</div>
			</div>
		</header>
		<div class="app-container">
			<div class="table-warper">
				<div class="table-tabbar">
					<span class="new-table-btn"></span>
					<div id="sheets-tabs" class="tabs-warper">
						<!--选项卡-->
					</div>
				</div>
				<div class="table-statusbar">
					<div id="selectionCellStatus" class="active-cont">A</div>
					<div class="formula-warper">
						<span class="formula-del"><i class="fa fa-times-circle"></i></span>
						<span class="formula-save"><i class="fa fa-check-circle"></i></span>
						<div class="formula-cont"><input id="formula-val" placeholder="单元格值域"/></div>
					</div>
				</div>
				<div class="table-container">
					<div id="sheets-container" class="table-warp">
						<!--数据表-->
					</div>
				</div>
			</div>
			<div class="opts-sidebar tab-box">
				<div class="opts-tabs">
					<span class="opts-tabs-item tab-nav active">
					单元格
					</span><span class="opts-tabs-item tab-nav">
					数据配置
					</span><span class="opts-tabs-item tab-nav">
					图表配置
					</span>
				</div>
				<div class="opts-warp tab-item active">
					<div class="opts-scroll-warp">
						<div id="styleopts" class="opts-box">
							<!--  -->
							
							<!--  -->
						</div>
					</div>
				</div>
				<div class="opts-warp tab-item">
					<div class="opts-scroll-warp">
						<div id="dbopts" class="opts-box">
							<!--  -->
							<!--  -->
						</div>
					</div>
				</div>
				<div class="opts-warp tab-item">
					<div class="opts-scroll-warp">
						<div id="chartopts" class="opts-box">
							<!--  -->
							<!--  -->
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="sheets-toolbar">
		</div>
	</div>
	<div id="loading"><i class="fa fa-lg fa-spin fa-spinner"></i><span></span></div>
</body>
<script type="text/javascript">
	window.nodeRequire = require;
	delete window.require;
	delete window.exports;
	delete window.module;
	const ipcRenderer = nodeRequire("electron").ipcRenderer;
	const nodeFS = nodeRequire('fs');
	const nodeCrypto = nodeRequire('crypto');

	var algorithm = 'aes-128-ecb';
	var key = '1A2b3C4d5E6f7G8h';
	var clearEncoding = 'utf8';
	var iv = "";
	var cipherEncoding = 'base64';

	function AESEncode(data){
		var cipher = nodeCrypto.createCipheriv(algorithm, key,iv);
		var cipherChunks = [];
    cipherChunks.push(cipher.update(data, clearEncoding, cipherEncoding));
    cipherChunks.push(cipher.final(cipherEncoding));
    return cipherChunks.join('');
	}
	function AESDecode(data){
  	var decipher = nodeCrypto.createDecipheriv(algorithm, key,iv);
    var plainChunks = [];
    plainChunks.push(decipher.update(data, cipherEncoding, clearEncoding));
    plainChunks.push(decipher.final(clearEncoding));
    return plainChunks.join('');
	}
</script>
<script src="assets/js/plugins/rule/full/ruleJS.all.full.js"></script>
<script type="text/javascript" src="assets/js/esl.js"></script>
<script type="text/javascript">
	require(['marker'],function(marker){
	  	'use strict';
		var tempdata={
			id:'paper1',
			name:'测试结构',
			sheets:[
				{
					id:'table1',
					name:'sheet 1',
					data:{},
					mergecells:[],
			groups:{},
			minrows:30,
			mincols:26
				}
			]
		};
		var currfile=null;
		var Marker=new marker(tempdata);
		$(document).on('click','#new-btn',function(event){
			event.preventDefault();
			Marker.open(null);
		});
		$(document).on('click','#save-btn',function(event){
			event.preventDefault();
			if(currfile!=null){
				saveFile(currfile);
			}else{
				ipcRenderer.send('openfilewindow-message', 'save');
			}
		});
		$(document).on('click','#open-btn',function(event){
			event.preventDefault();
			ipcRenderer.send('openfilewindow-message', 'open');
		});
		// 打开窗口成功
    	ipcRenderer.on('openfilewindow-reply', function(event,arg) {
		  var cmd=arg[0],filepath=arg[1];
		  if(!filepath) return;
		  $('#loading').show();
		  if(cmd=='open'){
		  	var sheets={};
		  	filepath.forEach(function(v,i){
		  		var f=nodeFS.readFileSync(v,'utf8');
		  		if(f!=''){
		  			var dedata=AESDecode(f);
		  			$.extend(true, sheets, JSON.parse(dedata));
		  		}
		  	});
		  	Marker.open(sheets);
			currfile=filepath.length>1?null:filepath[0];
		  }else if(cmd=='save'){
		  	saveFile(filepath);
		  }
		  $('#loading').hide('slow');
		});
		function saveFile(filepath){
			var data=AESEncode(JSON.stringify(Marker.save()));
		  	nodeFS.writeFile(filepath,data, 'utf8', function(err){
		  		if(err){
					alert(err);
				}else{
					alert('保存成功');
				}
		  	});
		}

		window.onresize=function(){
			Marker.refresh();
		};
 	});
</script>
</html>